package cz.gelion.shylock.invoice.entity

import javax.persistence.Entity
import javax.persistence.Table
import scala.beans.BeanProperty
import java.io.Serializable
import javax.persistence.Column
import javax.persistence.EmbeddedId
import javax.persistence.JoinColumn
import javax.persistence.OneToMany
import javax.persistence.ManyToOne
import cz.gelion.shylock.invoice.Log


@Entity
@Table(name="subject_unit_account")
class SubjectUnitAccount(p:SubjectUnitAccount.PK) extends Log {

  def this() = this(null)
  def this(acc:Account, su:SubjectUnit) = this(new SubjectUnitAccount.PK(acc,su))
  
  @EmbeddedId
  @BeanProperty
  var id:SubjectUnitAccount.PK = p
  
  @BeanProperty
  @Column(name="note")
  var note:String = _
  
  
  override def toString():String = {
    if (log.isDebugEnabled()) {
      super.toString + "{id=" + getId + "}" 
    } else {
      super.toString
    }
  }
  
}

object SubjectUnitAccount {
  class PK(a:Account,s:SubjectUnit) extends Serializable {
    
    def this() = this(null,null)
    
    @BeanProperty
    @ManyToOne
    @JoinColumn(name="account")
    var account:Account = a
    
    
    @BeanProperty
    @ManyToOne
    @JoinColumn(name="subject_unit")
    var subjectUnit:SubjectUnit = s
    
  }
}